/* 
	这个版本的头节点无数据,待解决
*/
#include <stdio.h>
#include <stdlib.h> 

struct list{
	char data;
	struct list *next;
};//终于解决了，原来问题在于C语言中对结构严格要求，即使用必须加struct

struct list *initialList(){	//是否可以在外面初始化头节点
	struct list *head = (struct list *)malloc(sizeof(struct list));
	head -> next = NULL;
	//head -> data = 'A';//头节点无数据可以注释掉
	return head;
}

void printListEle(struct list *head, int nul){
	struct list *temp = head -> next;//头节点只起标记作用
	//list *temp = head;//头节点又数据
	while (--nul){ 
		temp = temp -> next;
	}
	printf("%c \n",temp -> data);
}
		
void addList(struct list *head, int nul, char in){
	struct list *temp = head; 
	while(--nul){
			temp = temp -> next;  
  	}
	struct list *qemp = (struct list *)malloc(sizeof(struct list));
	qemp -> data = in;
 	qemp -> next = temp -> next;
 	temp -> next = qemp;
}
	
void printList(struct list *head){
	struct list *temp = head -> next;
	do{
		printf("%c ", temp -> data);
		temp = temp -> next;
	}while(temp);
}

void deleteListEle(struct list *head, int nul){
	struct list *temp = head;
		while(--nul){
			temp = temp  -> next;
 			}
	struct list *qemp = temp -> next;
		temp -> next = qemp -> next;
		free(qemp);
}

void deleteList(struct list *head){
	struct list *temp = head -> next;
	do{
		head -> next = temp -> next;
		free(temp);
		temp = head -> next;
	}while(temp);	//出现了溢出
}

int 
main(){
	
//	list *head = (list *)malloc(sizeof(list));
	struct list *head = initialList();
	addList(head, 1, 'B');
	addList(head, 2, 'C');
	addList(head, 3, 'D');
	addList(head, 4, 'E');
//	printListEle(head, 2);
	printList(head);
	deleteListEle(head, 2);
	printList(head);
	deleteList(head);
//	printListEle(head, 1);
}


